'''
Created on Sep 9, 2011

@author: Reprise
'''
import httplib
import datetime
import random


class httpAttack(object):
    '''
    classdocs
    '''

    def http_get(self, host, path, headers):
        try:
            conn = httplib.HTTPConnection(host)
            conn.request('GET', path, headers=headers)
            resp = conn.getresponse()
            body = resp.read()
        except Exception as e:
            raise Exception('Connection Error: %s' % e)
        finally:
            conn.close()
        if resp.status >= 400:
            raise ValueError('Response Error: %s, %s' %
                             (resp.status, resp.reason))
        return body


host = 'ec2-50-16-3-94.compute-1.amazonaws.com'
path = '/12345/12345678901234567890123456789012'
headers = {'User-Agent': 'Mozilla/5.0', 'Content-Type': 'text/xml'}

f = open('/tmp/resultsfile_network.dat', 'w')
f.write('Request\tRequestTime\tResponseTime\tResponse\n')
f.close()

anAttack = httpAttack()
i = 0
for i in range(100):
    random.seed()
    hash = random.getrandbits(128)
    f = open('/tmp/resultsfile_network.dat', 'a')
    f.write('%s\t%s' % (i, datetime.datetime.now()))
    #path = '/50005/%032x' % (hash)
    path = '/50005/12345'
    #print path
    respo = anAttack.http_get(host, path, headers)

    f.write('\t%s\t%s\n' % (datetime.datetime.now(), respo))
    f.close()
